package com.exam.sacrifice.ui.mine;

import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.view.View;

import com.exam.commonbiz.base.BaseActivity;
import com.exam.commonbiz.base.BaseViewModel;
import com.exam.commonbiz.bean.BottomSheetDialogInfo;
import com.exam.commonbiz.util.AppManager;
import com.exam.commonbiz.util.CommonCallBack;
import com.exam.commonbiz.util.DialogUtils;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.commonbiz.widget.CommonBottomSheetDialog;
import com.exam.sacrifice.R;
import com.exam.sacrifice.databinding.ActivitySettingBinding;
import com.exam.sacrifice.ui.login.LoginActivity;
import com.mt.mtloadingmanager.LoadingDialog;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends BaseActivity<BaseViewModel, ActivitySettingBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initData() {

        binding.include.tvTitle.setText("设置");
        binding.include.ivback.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                finish();
            }
        });

        binding.llNotification.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {

                Intent localIntent = new Intent();
                localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
                context.startActivity(localIntent);
            }
        });

        binding.llYinsi.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(PrivacySettingsActivity.class);
            }
        });

        binding.llAbout.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(AboutActivity.class);
            }
        });

        binding.llCache.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                DialogUtils.showCustomConfirmDialog(SettingActivity.this,
                        "系统提示",
                        "确认清除缓存吗？",
                        "确认",
                        "取消",
                        new CommonCallBack() {
                            @Override
                            public void callback(int postion, Object object) {
                                if (postion == 0) {
                                    loadingManager.show("缓存清除中");
                                    // 保存操作
                                    new Handler().postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            binding.tvCache.setText("0MB");
                                            loadingManager.hideSuccess("清除完毕", new LoadingDialog.OnDialogDismissedListener() {
                                                @Override
                                                public void onDialogDismissed() {

                                                }
                                            });
                                        }
                                    }, 1500);
                                }
                            }
                        });
            }
        });

        binding.btnLogout.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                List<BottomSheetDialogInfo> bottomSheetDialogInfoList = new ArrayList<>();
                bottomSheetDialogInfoList.add(new BottomSheetDialogInfo(0, "退出"));
                new CommonBottomSheetDialog().show(context, bottomSheetDialogInfoList, new CommonCallBack() {
                    @Override
                    public void callback(int postion, Object object) {
                        actionStart(LoginActivity.class);
                        AppManager.getAppManager().finishAllActivity();
                    }
                });
            }
        });
    }
}